//
//  DutyViewController.m
//  Nurse
//
//  Created by Sunny on 13-12-13.
//  Copyright (c) 2013年 RainSets. All rights reserved.
//

#import "DutyViewController.h"
#import "DutyViewCell.h"
#import "DutyScreeningView.h"
#import "DutyViewListCell.h"
#import "DutyViewButtonCell.h"
#import "DutyScanningViewCell.h"


#import "PatientService.h"
#import "OrdersService.h"
#import "ScanService.h"
#import "OperatorService.h"
#import "BlocksKit.h"
#import "BlocksKit+UIKit.h"
#import "MBProgressHUD.h"
#import "SVProgressHUD.h"
#import "EGORefreshTableHeaderView.h"
@interface CellInfoData : NSObject{
    
}

@property(nonatomic,assign)BOOL isOpen;

@end

@implementation CellInfoData



//自定义排序方法
-(NSComparisonResult)compareCellInfo:(CellInfoData *)infoData{
    NSComparisonResult result = [[NSNumber numberWithBool:infoData.isOpen] compare:[NSNumber numberWithBool:self.isOpen]];
    
    return result;
}

@end

@interface DutyViewController ()
@property(nonatomic,strong)NSMutableArray* tasks;

-(NSArray*)processTasksData:(NSArray*)rawData;
-(void)onReceiveScanData:(NSNotification*)notification;

@end



@implementation DutyViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        //根据消息的标题不同区分各个VIEW接受的对象
        NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
        [nc addObserver:self selector:@selector(onReceiveScanData:) name:@"duty" object:nil];
        
    }
    return self;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [App showTabbar];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

     self.title  = @"任务";
//    [self setleftBarButtonItem:@"screening_leftBar.png" Event:@selector(leftBar_clicked:)];
    
    
     [self setleftBarButtonItem:@""orImaged:@"head-icon_05.png" Event:@selector(leftBar_clicked:)];
    
    [self setrightBarButtonItem:@""orImaged:@"head-icon_02.png" Event:@selector(rightBar_clicked:)];
    
    
    if (_refreshHeaderView == nil) {
        EGORefreshTableHeaderView *view1 = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0-self.table_View.bounds.size.height, self.view.frame.size.width, self.table_View.bounds.size.height)];
        view1.delegate = self;
        [self.table_View addSubview:view1];
        _refreshHeaderView = view1;
       // [view1 release];
    }
    [_refreshHeaderView refreshLastUpdatedDate];
    
    

//    
//    for (int i=0; i<10; i++) {
//       
//        NSMutableDictionary *dic=[[NSMutableDictionary alloc]init];
//        [dic setObject:@"检查血压" forKey:@"name"];
//        //[dic setObject:@"检查血压" forKey:@"img"];
//        NSMutableArray *arr=[[NSMutableArray alloc]init];
//        [arr addObject:@"1"];
//        [arr addObject:@"1"];
//        [arr addObject:@"1"];
//        [dic setObject:arr forKey:@"list"];
//        arr=nil;
//        [_dataList addObject:dic];
//        dic=nil;
//        
//    }
    
    
//    CellInfoData *infoData = [[CellInfoData alloc] init];
//    infoData.isOpen  = NO;
   // [_dataList addObject:infoData];
    self.table_View.sectionFooterHeight = 0;
    self.table_View.sectionHeaderHeight = 0;
    

    [self setupData];
    CellInfoData *infoData = [[CellInfoData alloc] init];
    infoData.isOpen  = NO;
 
    
    
  
//    [[Captuvo sharedCaptuvoDeviceDebug] addCaptuvoDelegate:self];
//    [[Captuvo sharedCaptuvoDevice] startDecoderHardware] ;
//    [[Captuvo sharedCaptuvoDevice]enableCaptuvoDebug:NO];

    
}

- (void)reloadTableViewDataSource{
    _reloading = YES;
    //开始刷新后执行后台线程，在此之前可以开启HUD或其他对UI进行阻塞
    //[NSThread detachNewThreadSelector:@selector(doInBackground) toTarget:self withObject:nil];
    //[self setupData];
    
}


- (void)doneLoadingTableViewData{
    NSLog(@"===加载完数据");
    _reloading = NO;
    [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.table_View];
    [self setupData];
}
#pragma mark –
#pragma mark UIScrollViewDelegate Methods
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
    
} - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
}
#pragma mark –
#pragma mark EGORefreshTableHeaderDelegate Methods
- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
    [self reloadTableViewDataSource];
    [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
}

- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
    return _reloading;
}
- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
    return [NSDate date];
}

-(void)setupData{
    NSString* wardCode = [[OperatorService sharedInstance]currentOperatorWardCode];
  // if ([wardCodes count] > 0) {
       // NSString* wardCode = [wardCodes objectAtIndex:0];
    __weak DutyViewController* this = self;
    [SVProgressHUD showWithStatus:@"任务加载中..." maskType:SVProgressHUDMaskTypeBlack];

    [[OrdersService sharedInstance] queryDutiesForBq:wardCode withSuccessHandler:^(id result) {
        //NSLog(@"任务.....................");
        //NSLog(@"任务:%@",result);
        [SVProgressHUD dismiss];
       // _dataList = [[NSMutableArray alloc] init];

        if ([result isKindOfClass:[NSArray class]]) {
            this.tasks= result;
            
            
            _dataList = [[OrdersService sharedInstance]processTasksData:this.tasks];
//            CellInfoData *infoData = [[CellInfoData alloc] init];
//            infoData.isOpen  = NO;
//            [_dataList addObject:infoData];
            [this.table_View reloadData];
            AppDelegate  *appDelegate = App;
            
            //根据isScan 确定重新提交消息内容触发后续接受消息的事件
            if(appDelegate.isScan)
            {
                
                [[ScanService sharedInstance]postDataReceivedNotify:appDelegate.Scandata andviewname:@"duty"];
                //[[DataEngine sharedInstance]showMessage:appDelegate.Scandata withTitle:@"跳转任务扫描顺序错误"];
            }

        }
        
    } andFailHandler:^(NSError *error, NSString *title) {
         [SVProgressHUD dismiss];
        [[DataEngine sharedInstance]showMessage:[error description] withTitle:@"获取任务信息时失败"];
    }];
    
    

    
}


-(void)onReceiveScanData:(NSNotification*)notification{
//-(void)decoderDataReceived:(NSString *)smdata{
  if ([self.navigationController visibleViewController] == self) {
        
        NSDictionary* userinfo = [notification userInfo];
        NSString* data = [userinfo valueForKey:@"data"];
        NSArray* datearray = [data componentsSeparatedByString:@"|"];
        NSString* datebz = [datearray objectAtIndex:0];
   
    
    
    if ([datebz isEqualToString:@"BR"]) {
//        if (self.isOpen) {
//            NSDictionary* tasks = [_dataList objectAtIndex:self.selectIndex.section];
//            [tasks setValue:@"1" forKey:@"scanStatus"];
//            [self.table_View reloadData];
//        }else{
//            [[DataEngine sharedInstance]showMessage:@"请先扫描需要执行的医嘱项目" withTitle:@"扫描顺序错误"];
//        }
            if (self.isOpen) {
                NSDictionary* tasks = [_dataList objectAtIndex:self.selectIndex.section];
                NSArray* brarray = [data componentsSeparatedByString:@"|"];
                NSString* zyh = [brarray objectAtIndex:1];
                NSString* PaientID = [tasks valueForKey:@"zyh"];
                
                
                //        NSString* zyzbh = [array objectAtIndex:0];
                //        NSString* rwrq = [array objectAtIndex:1];
                if ([zyh isEqualToString:PaientID]){
                    [tasks setValue:@"1" forKey:@"scanStatus"];
                    [self.table_View reloadData];
                }
                else
                {[[DataEngine sharedInstance]showMessage:
                  [NSString stringWithFormat:@"当前扫描病人=%@。\n医嘱所属住院号=%@",[zyh substringToIndex: 6],[PaientID substringToIndex: 6]]
                                               withTitle:@"任务扫描病人错误"];
                }
            }else{
            [[DataEngine sharedInstance]showMessage:@"请先扫描需要执行的医嘱项目" withTitle:@"任务扫描顺序错误"];
        }

    }
    //长度超过6为医嘱条码
  if ([datebz isEqualToString:@"SY"]) {
        NSArray* array = [data componentsSeparatedByString:@"|"];
        
        NSString* zyzbh = [array objectAtIndex:1];
        NSString* rwrqsj = [array objectAtIndex:2];
        
        
        NSString* keyValue = [NSString stringWithFormat:@"%@%@",zyzbh,rwrqsj];

        BOOL found = NO;
        for (int i=0;i<[_dataList count];i++) {
            NSDictionary* tasks = [_dataList objectAtIndex:i];
            NSString* taskKey = [tasks valueForKey:@"keyValue"];
            //NSString* scanStatus = [tasks valueForKey:@"scanStatus"];
            if ([taskKey isEqualToString:keyValue]) {
                NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:i];
                NSLog(@"select to indexPath:%@",indexPath);
                [self.table_View selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop];
                if (!self.isOpen) {
                    
                    [self tableView:self.table_View didSelectRowAtIndexPath:indexPath];
                    
                    
                }else{
                    if (self.selectIndex.section != indexPath.section) {
                        [self tableView:self.table_View didSelectRowAtIndexPath:self.selectIndex];
                        [self tableView:self.table_View didSelectRowAtIndexPath:indexPath];
                       

                    }
                     [tasks setValue:@"0" forKey:@"scanStatus"];
                    

                }
                //[tasks setValue:@"1" forKey:@"scanStatus"];
                NSNumber* status = [tasks valueForKey:@"status"];
                
                if ([status intValue] == 1) {
                    [[DataEngine sharedInstance]
                     showMessage:@"该条医嘱信息已经执行过了!"
                     withTitle:@"提醒核对医嘱信息"];
                }
                found = YES;
                break;
            }
        }
        if (!found) {
            [[DataEngine sharedInstance]
             showMessage:[NSString stringWithFormat:@"主医嘱编号=%@。\n任务日期=%@",zyzbh,rwrqsj]
             withTitle:@"没有找到下列医嘱信息"];
        }
        
    }
      
    
    
    
    }
}




#pragma mark - Table view data source



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [_dataList count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
//    CellInfoData *infoData = [_dataList objectAtIndex:section];
    BOOL op = [[[_dataList objectAtIndex:section] valueForKey:@"isOpen"] boolValue];
    if (op) {
        if (self.selectIndex.section == section) {
            
            if ([[[_dataList objectAtIndex:section] objectForKey:@"list"] count]>0) {
                return [[[_dataList objectAtIndex:section] objectForKey:@"list"] count] + 2;
            }
        }
    }
    return 1;
}
- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.row==0) {
        return 63;
    }
    return 45;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    // NSLog(@"indexPath.row=%d,indexPath.section=%d",indexPath.row,indexPath.section);
    
    NSInteger taskIndex = indexPath.section;
    
    NSDictionary* taskRecord = [_dataList objectAtIndex:taskIndex];
    
    BOOL isOP = [[taskRecord valueForKey:@"isOpen"] boolValue];
    
    NSString* taskType = [taskRecord valueForKey:@"type"];
    
    NSString* scanStatus = [taskRecord valueForKey:@"scanStatus"];
    //CellInfoData *infoData = [_dataList objectAtIndex:indexPath.section] ;
    if (isOP && self.selectIndex.section == indexPath.section && indexPath.row!=0) {
        
        NSArray *list = [[_dataList objectAtIndex:self.selectIndex.section] objectForKey:@"list"];
        if(indexPath.row==[list count]+1){
            ///////////////////////////////////////
            /*************设置为0 规定一定要扫描病人***************/
            if ([scanStatus isEqualToString:@"0"]) {
                /****************************/
                static NSString *CellIdentifier = @"DutyScanningViewCell";
                
                DutyScanningViewCell *cell = (DutyScanningViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                if(cell==nil){
                    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DutyScanningViewCell" owner:self options:nil];
                    cell = [nib objectAtIndex:0];
                }
                cell.img.image=[UIImage imageNamed:@"scan-icon-s.png"];
                cell.describeLab.text=@"请扫描病人信息";
                
                
                cell.selectionStyle=UITableViewCellSelectionStyleNone;
                return cell;
                
            }else{
                //下面三个按钮
                static NSString *CellIdentifier = @"DutyViewButtonCell";
                
                DutyViewButtonCell *cell = (DutyViewButtonCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                if(cell==nil){
                    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DutyViewButtonCell" owner:self options:nil];
                    cell = [nib objectAtIndex:0];
                    [cell.completeBtn setTitle:@"已完成" forState:UIControlStateNormal];
                    [cell.notInBtn setTitle:@"病人不在" forState:UIControlStateNormal];
                    [cell.refusedBtn setTitle:@"病人拒绝" forState:UIControlStateNormal];
                    
                    
                    cell.completeBtn.titleLabel.font=[UIFont systemFontOfSize:14.f];
                    cell.notInBtn.titleLabel.font=[UIFont systemFontOfSize:14.f];
                    cell.refusedBtn.titleLabel.font=[UIFont systemFontOfSize:14.f];
                    
                    [cell.completeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    [cell.notInBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                    [cell.refusedBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                    
                    
                    [cell.completeBtn setBackgroundColor:NavigationBarColor];
                    [cell.notInBtn setBackgroundColor:[UIColor colorWithRed:223/255.0 green:228/255.0 blue:230/255.0 alpha:1.0]];
                    [cell.refusedBtn setBackgroundColor:[UIColor colorWithRed:223/255.0 green:228/255.0 blue:230/255.0 alpha:1.0]];
                    
                    NSMutableArray* idArray = [NSMutableArray array];
                    
                    for (NSDictionary* dict in list) {
                        NSString* taskID = [dict valueForKey:@"任务编号"];
                        [idArray addObject:taskID];
                    }
                    
                    __block NSString* allTaskID = [idArray componentsJoinedByString:@","];
                    __weak DutyViewController* this = self;
                    
                    [cell.completeBtn bk_addEventHandler:^(id sender) {
                        NSLog(@"completeBtn");
                        //__block NSString* innerAllTaskID = allTaskID;
                        NSLog(@"innerAllTaskID:%@",allTaskID);
                        [[OrdersService sharedInstance]executeDutyForID:allTaskID withStatus:@"1" withSuccessHandler:^(id result) {
                            [[DataEngine sharedInstance]showMessage:@"完成任务成功" withTitle:@"执行任务"];
                            [this tableView:this.table_View didSelectRowAtIndexPath:this.selectIndex];
                            [this setupData];
                        } andFailHandler:^(NSError *error, NSString *title) {
                            [[DataEngine sharedInstance]showMessage:[error description] withTitle:@"执行任务失败"];
                            //[this.table_View reloadData];
                        }];
                        
                    } forControlEvents:UIControlEventTouchUpInside];
                    
                    [cell.notInBtn bk_addEventHandler:^(id sender) {
                        NSLog(@"notInBtn");
                        [[OrdersService sharedInstance]executeDutyForID:allTaskID withStatus:@"3" withSuccessHandler:^(id result) {
                            [[DataEngine sharedInstance]showMessage:@"提交病人不在状态成功" withTitle:@"执行任务"];
                            [this setupData];
                        } andFailHandler:^(NSError *error, NSString *title) {
                            [[DataEngine sharedInstance]showMessage:[error description] withTitle:@"执行任务失败"];
                        }];
                        
                    } forControlEvents:UIControlEventTouchUpInside];
                    
                    [cell.refusedBtn bk_addEventHandler:^(id sender) {
                        NSLog(@"notInBtn");
                        [[OrdersService sharedInstance]executeDutyForID:allTaskID withStatus:@"2" withSuccessHandler:^(id result) {
                            [[DataEngine sharedInstance]showMessage:@"提交病人拒绝状态成功" withTitle:@"执行任务"];
                            [this setupData];
                        } andFailHandler:^(NSError *error, NSString *title) {
                            [[DataEngine sharedInstance]showMessage:[error description] withTitle:@"执行任务失败"];
                        }];
                        
                    } forControlEvents:UIControlEventTouchUpInside];
                    
                    
                }
                
                cell.selectionStyle=UITableViewCellSelectionStyleNone;
                return cell;
                
            }
            ///////////////////////////////////////
        }else{
            static NSString *CellIdentifier = @"DutyViewListCell";
            
            DutyViewListCell *cell = (DutyViewListCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if(cell==nil){
                NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DutyViewListCell" owner:self options:nil];
                cell = [nib objectAtIndex:0];
            }
            
            
            if (indexPath.row <= [list count] ) {
                NSLog(@"index path row:%d",indexPath.row);
                NSDictionary* task = [list objectAtIndex:indexPath.row-1];
                cell.nameLab.text = [task valueForKey:@"任务内容"];
                NSLog(@"nr:%@",[task valueForKey:@"任务内容"]);
                cell.numberLab.text = [NSString stringWithFormat:@"%@ %@",[task valueForKey:@"剂量"],[task valueForKey:@"单位"]];
                
            }
            
            
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            return cell;
        }
        
    }else
    {
        
        static NSString *CellIdentifier = @"DutyViewCell";
        
        DutyViewCell *cell = (DutyViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if(cell==nil){
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DutyViewCell" owner:self options:nil];
            cell = [nib objectAtIndex:0];
            cell.hookimg.image=[UIImage imageNamed:@"current-icon_s.png"];
            
        }
        
        cell.headimg.image=[UIImage imageNamed:@"patient-icon-s.png"];
        cell.hookimg.hidden=NO;
        cell.backgroundColor=[UIColor colorWithRed:140/255.0 green:201/255.0 blue:233/255.0 alpha:0.6];
        
        if ([taskType isEqualToString:@"给药"]) {
            cell.img.image=[UIImage imageNamed:@"task-icon-02.png"];
        }
        else{
            cell.img.image=[UIImage imageNamed:@"task-icon-03.png"];
        }
        NSNumber* status = [taskRecord valueForKey:@"status"];
        if ([status intValue] == 0) {
            cell.headimg.image=[UIImage imageNamed:@"patient-icon-s_grey.png"];
            cell.hookimg.hidden=YES;
            cell.backgroundColor=[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:0.6];
        }
        
        
        
        cell.contentLab.text=[taskRecord valueForKey:@"title"];
        cell.timeLab.text=[NSString stringWithFormat:@"%@",[taskRecord valueForKey:@"dateTime"]];
        cell.nameLab.text= [taskRecord valueForKey:@"xm"];
        
        
        //cell.titleLabel.text=@"111";
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;
    }
}


#pragma mark - Table view delegate


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
//    if (indexPath.row == 0) {
//        if ([indexPath isEqual:self.selectIndex]) {
//            self.isOpen = NO;
//            [self didSelectCellRowFirstDo:NO nextDo:NO];
//            self.selectIndex = nil;
//            
//        }else
//        {
//            if (!self.selectIndex) {
//                self.selectIndex = indexPath;
//                [self didSelectCellRowFirstDo:YES nextDo:NO];
//                
//            }else
//            {
//                
//                [self didSelectCellRowFirstDo:NO nextDo:YES];
//            }
//        }
//        
//    }else
//    {
//        //        NSDictionary *dic = [_dataList objectAtIndex:indexPath.section];
//        //        NSArray *list = [dic objectForKey:@"list"];
//        //        NSString *item = [list objectAtIndex:indexPath.row-1];
//        //        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:item message:nil delegate:nil cancelButtonTitle:@"取消" otherButtonTitles: nil] ;
//        //        [alert show];
//    }
//  [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
//    CellInfoData *infoData = [_dataList objectAtIndex:indexPath.section];
    if (indexPath.row != 0) {
        return;
    }
    self.selectIndex = indexPath;
    BOOL isOp = [[[_dataList objectAtIndex:indexPath.section] valueForKey:@"isOpen"] boolValue];
    isOp = !isOp;
    
    [[_dataList objectAtIndex:indexPath.section] setValue:[NSNumber numberWithBool:isOp] forKey:@"isOpen"];
    
   
//    [_dataList replaceObjectAtIndex:indexPath.section withObject:dictT];
//    [_dataList replaceObjectAtIndex:indexPath.section withObject:dictT];
    
//    NSArray *sortedArray = [_dataList sortedArrayUsingSelector:@selector(compareCellInfo:)];
//   _dataList = [[NSMutableArray alloc] initWithArray:sortedArray];
    [self.table_View reloadData];
}



- (void)didSelectCellRowFirstDo:(BOOL)firstDoInsert nextDo:(BOOL)nextDoInsert
{
    self.isOpen = firstDoInsert;
    
    //    UITableViewCell *cell = [self.expansionTableView cellForRowAtIndexPath:self.selectIndex];
    //    [cell changeArrowWithUp:firstDoInsert];
    
    [self.table_View beginUpdates];
    
    int section = self.selectIndex.section;
    
    NSDictionary* taskRecord = [self.tasks objectAtIndex:section];
    
    int contentCount = [[[_dataList objectAtIndex:section] objectForKey:@"list"] count];
	NSMutableArray* rowToInsert = [[NSMutableArray alloc] init];
	for (NSUInteger i = 1; i < contentCount + 2; i++) {
		NSIndexPath* indexPathToInsert = [NSIndexPath indexPathForRow:i inSection:section];
		[rowToInsert addObject:indexPathToInsert];
	}
	
	if (firstDoInsert)
    {   [self.table_View insertRowsAtIndexPaths:rowToInsert withRowAnimation:UITableViewRowAnimationTop];
    }
	else
    {
        [self.table_View deleteRowsAtIndexPaths:rowToInsert withRowAnimation:UITableViewRowAnimationTop];
    }
    
	rowToInsert=nil;
	
	[self.table_View endUpdates];
    if (nextDoInsert) {
        self.isOpen = YES;
        self.selectIndex = [self.table_View indexPathForSelectedRow];
        [self didSelectCellRowFirstDo:YES nextDo:NO];
    }
    if (self.isOpen) [self.table_View scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionTop animated:YES];
}




-(void)leftBar_clicked:(id)sender
{
    
    DutyScreeningView *screeningView = [[[NSBundle mainBundle] loadNibNamed:@"DutyScreeningView" owner:self options:nil]lastObject];
    screeningView.frame=CGRectMake(0, self.view.frame.origin.y-44-20, 320, self.view.frame.size.height+44+20);
   // NSLog(@"screeningView=%@",screeningView);
    [ModelClass animationTransitionMoveIn:screeningView];
    
    
    [screeningView setViewStyle];
    AppDelegate *app=(AppDelegate *)[[UIApplication sharedApplication]delegate];
    [app.window  addSubview:screeningView];
        
}


-(void)rightBar_clicked:(id)sender{
    //[self setupData];
    

    
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
